package servlets;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import domain.IDAOContact;

public class IndexContactAction extends Action {
	public ActionForward execute(final ActionMapping pMapping,
			ActionForm pForm, final HttpServletRequest request,
			final HttpServletResponse response) {
		 if (request.getMethod().equals("GET")){
			ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServlet().getServletContext());
			IDAOContact dao = (IDAOContact) context.getBean("daocontact");
			request.setAttribute("contacts", dao.getAllContacts().toArray());
			return pMapping.findForward("indexContacts");
		}
		return null;
	}
}